package pages;

import core.TestBase;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import utils.Log4Test;

import java.util.List;


public class LaptopPage extends GeneralPage {

    protected By ActiveTab = By.xpath("//td[@id='computers-notebooks']/div/a");
    protected By AppleLink = By.linkText("Apple");
    protected By ManufacturesDiv = By.xpath("//div[1]/div[4]/div/div/div[2]/div[3]/ul/li[2]/ul/li");
    protected By ManufacturesDivApple = By.xpath("//div[1]/div[4]/div/div/div[2]/div[3]/ul/li[2]/ul/li");
    protected WebElement LaptopElem;
    protected WebElement AppleElem;
    protected List<WebElement> ManufacturesList;

    // 4. Verify that the page is Ноутбуки and tab Ноутбуки, планшеты и компьютеры is active
    public String verifyActiveTabLaptop()
    {
        Log4Test.info("Verify Page Laptop and Planshets is Active");
        WebElement LaptopElem = webDriver.findElement(ActiveTab);
        return LaptopElem.getAttribute("name");
    }

    // 5. On the left side of the page there are 8 manufactures under Производители, you should verify that all 8 manufactures are present

    public List<WebElement> FindManufactureslist()
    {
        List<WebElement> ManufacturesList = webDriver.findElements(ManufacturesDiv);
        Log4Test.info("Number of laptop manafuctures is 8");
        return ManufacturesList;
    }

    //6.  all manufactures and if it contains Apple - click Apple manufacture

       public void Appleclick (){
         Log4Test.info("AppleClick");
         webDriver.findElement(AppleLink).click();
         }

    //This variant doesn't work!!!
    public void AppleManufactur() {

        for (WebElement AppleElem : ManufacturesList = webDriver.findElements(ManufacturesDiv)) {
            if (AppleElem.getText().contains("Apple")) {
                Log4Test.info("Manafacture is apple");
                AppleElem.click();
                break;
            }
        }
    }
}